package jplat.tools.file;
import java.io.IOException;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import jplat.error.exception.JSystemException;
import jplat.tools.config.JBusConfig;

/**
  * Title: FtpClientConnector 
 *  Description: FTP服务连接类。
  * @version 1.0  
  */
public class FtpClientConnector
{
	private Logger logger = Logger.getLogger(FtpTool.class);
	private FTPClient ftpClient = new FTPClient();
	private final static FtpClientConnector INSTANCE = new FtpClientConnector();
	
	private FtpClientConnector(){
		try{
 		      ftpClient.connect(JBusConfig.FTP_IP); 
              ftpClient.login(JBusConfig.FTP_USER,JBusConfig.FTP_PWD);
             //设置上传目录 
              ftpClient.changeWorkingDirectory(JBusConfig.FTP_PATH); 
              ftpClient.setBufferSize(1024); 
              ftpClient.setControlEncoding("GBK"); 
              //设置文件类型（二进制） 
              ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); 
		}catch(Exception e ){
			logger.error("error ftpclient:"+e.getMessage());
			return ;
		}
	};
	
	public static FtpClientConnector getInstance(){
		return INSTANCE;
	}
	
	public FTPClient getClient(){
		return ftpClient;
	}
	
}  
